﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class qtleft : System.Web.UI.UserControl
{
    public string ngg;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["usersidx"] != null)
        {
            Panel2.Visible = true;
            Panel1.Visible = false;
        }
        else
        {
            Panel1.Visible = true;
            Panel2.Visible = false;
        }
        if (!IsPostBack)
        {
            ListItem it0 = new ListItem();
            it0.Text = "管理员";
            it0.Value = "0";
            type.Items.Add(it0);
            ListItem it2 = new ListItem();
            it2.Text = "用户";
            it2.Value = "2";
            type.Items.Add(it2);

            string sql;
            sql = "select top 4 * from lianjie order by id desc";
            getdatayqlj(sql);
        }
    }

    //友情链接展示功能方法
    private void getdatayqlj(string sql)
    {
        DataSet result = new DataSet();
        result = new Class1().hsggetdata(sql);
        if (result != null)
        {
            if (result.Tables[0].Rows.Count > 0)
            {
                DataGridyqlj.DataSource = result.Tables[0];
                DataGridyqlj.DataBind();
            }
            else
            {
                DataGridyqlj.DataSource = null;
                DataGridyqlj.DataBind();
            }
        }
    }


    //登录功能实现方法
    protected void login_Button_Click(object sender, EventArgs e)
    {
        if (loginname.Text.ToString().Trim() == "" || loginpw.Text.ToString().Trim() == "")
        {
            Response.Write("<script>javascript:alert('请输入完整');location.href='default.aspx';</script>");
            Response.End();
        }
        string sql = "";
        sql = "select * from users where shenhe='yes' and loginname='" + loginname.Text.ToString().Trim() + "' and loginpw='" + loginpw.Text.ToString().Trim() + "' and type='" + type.SelectedItem.Value.ToString().Trim() + "' ";
        DataSet dsresult = new DataSet();
        dsresult = new Class1().hsggetdata(sql);
        if (dsresult != null)
        {
            if (dsresult.Tables[0].Rows.Count > 0)
            {
                Session["usersid"] = dsresult.Tables[0].Rows[0]["id"].ToString().Trim();
                Session["usersidx"] = dsresult.Tables[0].Rows[0]["id"].ToString().Trim();
                Session["loginname"] = dsresult.Tables[0].Rows[0]["loginname"].ToString().Trim();
                Session["type"] = dsresult.Tables[0].Rows[0]["type"].ToString().Trim();
                Session["typename"] = dsresult.Tables[0].Rows[0]["typename"].ToString().Trim();
                Response.Redirect("default.aspx");
            }
            else
            {
                Response.Write("<script>javascript:alert('对不起，用户名或密码不正确，或您的帐号未经审核!');</script>");
            }
        }
        else
        {
            Response.Write("<script>javascript:alert('登陆失败，用户名或密码错误，或您的帐号未经审核!');</script>");
        }
    }

    //跳转到注册功能实现方法
    protected void reg_Click(object sender, EventArgs e)
    {
        Response.Redirect("users_addqian.aspx");
    }
    //跳转到退出功能实现方法
    protected void logout_Click(object sender, EventArgs e)
    {
        Response.Redirect("userlogout.aspx");
    }
    //跳转到进入后台管理功能实现方法
    protected void main_Click(object sender, EventArgs e)
    {
        Response.Redirect("main.aspx");
    }


}//ascx封装了可以在多个页面中重用的特定功能和行为。这些控件可以包含HTML、代码和其他Web或用户控件，
//并被保存为独立文件，通常不直接通过URL访问，而是被集成到aspx页面中
